package com.sky.controller.user;

import com.sky.constant.CacheKeyRuleConstant;
import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@Api(tags = "C端-套餐接口")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 根据分类 id 查询套餐
     * @param categoryId
     * @return
     */
    @Cacheable(cacheNames = CacheKeyRuleConstant.SET_MEAL_KEY, key = "#categoryId")
    @ApiOperation("根据分类 id 查询套餐")
    @GetMapping("/list")
    public Result<List<Setmeal>> listByCategoryId(Long categoryId) {
        Setmeal setmeal = Setmeal.builder()
                .categoryId(categoryId)
                .status(StatusConstant.ENABLE)
                .build();
        List<Setmeal> setmealList =  setmealService.listByCategoryId(setmeal);
        return Result.success(setmealList);
    }

    /**
     * 根据套餐 id 获取套餐菜品信息
     * @param sid
     * @return
     */
    @ApiOperation("根据套餐 id 获取套餐菜品信息")
    @GetMapping("/dish/{sid}")
    public Result<List<DishItemVO>> getDishItemsById(@PathVariable  Long sid) {
        List<DishItemVO> dishItemVOList = setmealService.getDishItemsById(sid);
        return Result.success(dishItemVOList);
    }

}
